var fs = require('fs')
const dirCache={};
function writeFileByUser(filePath){
    if (!fs.existsSync(filePath)) mkdir(filePath); 
}

function mkdir(filePath) {
    const arr=filePath.split('/');
    let dir=arr[0];
    for(let i=1;i<arr.length;i++){
        if(!dirCache[dir]&&!fs.existsSync(dir)){
            dirCache[dir]=true;
            fs.mkdirSync(dir);
        }
        dir=dir+'/'+arr[i];
    }
    fs.writeFileSync(filePath, '')
}


/*
接口设计
登陆(验证码、登陆、忘记密码、修改密码)
用户(关注列表、关注、取消关注、)
帖子(发布、详情、点赞、)
聊天(列表、)
*/ 
var str = `/api/login/login
/api/login/code
/api/login/change
/api/user/careLsit
/api/user/care
/api/user/info
/api/post/post
/api/post/detail
/api/post/like
/api/chat/list
/api/file/upload
`
var file = '0.my-auto.js'

var sTemplete = (e,url)=>{
    return `${e}(data){
        return http('POST','${url}',data)
    },`
}

var uTemplete = (e)=>{
    return `async do${e}(data){
         res = await this.service.${e}();
         this.list = res.data;
    },`
}
var mTemplete = (url)=>{
    return `'${url}':{
		"code": 0,
	    "data": Mock.mock({ 
		
	    })	
	},`
}
var s='',u='',m='';
str.split("\n").map(e=>{
 
   if(!e)return;
   var tmp = e.split("/").pop()
   // console.log(tmp)
   s += sTemplete(tmp,e) + '\n'
   u += uTemplete(tmp) + '\n'
   m += mTemplete(e) + '\n'
}) 

fs.writeFileSync(file,[s,u,m].join('\n')) 